package com.ay.weixin.fdc.boss.menu.db;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import lizar.db.ibatis.Dao;

import com.ay.weixin.fdc.boss.menu.domain.Menu;

public class IbatisMenuDao extends Dao {
	
	
	public List<Menu> getAllByWxprojectId(long wxproject_id) throws SQLException{
		return (List<Menu>)this.sqlMapper.queryForList("menu.getAllByWxprojectId",wxproject_id);
	}
	
	public	Menu get(long wxproject_id,String key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("key", key);
		keys.put("wxproject_id", wxproject_id);
		return (Menu)this.sqlMapper.queryForObject("menu.get",keys);
	}
	
	public int size(long wxproject_id) throws SQLException{
		return (Integer)this.sqlMapper.queryForObject("menu.size",wxproject_id);
	}
	
	public int getMaxPos(long wxproject_id) throws SQLException{
		Integer max=(Integer)this.sqlMapper.queryForObject("menu.getMaxPos",wxproject_id);
		if(max==null){
			return 0;
		}
		return max+1;
	}
	
	public void insert(Menu menu) throws SQLException{
		this.sqlMapper.insert("menu.insert",menu);
	}
	
	public void update(Menu menu) throws SQLException{
		this.sqlMapper.insert("menu.update",menu);
	}
	
	public void delete(long wxproject_id,String key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("key", key);
		keys.put("wxproject_id", wxproject_id);
		this.sqlMapper.delete("menu.delete",keys);
	}
	
	public boolean exist(long wxproject_id,String key) throws SQLException{
		Map<String,Object> keys=new LinkedHashMap<String,Object>();
		keys.put("key", key);
		keys.put("wxproject_id", wxproject_id);
		Object o=this.sqlMapper.queryForObject("menu.exist",keys);
		if(o==null)return false;
		return true;
	}
}
